<?php
$config_file = parse_ini_file("../../properties/config.ini");
$include_path = "../";
include_once("../util/log_writer.php");
require_once("plantlib.php");
$lw = LogWriter::getInstance("../../properties/log4php-level2.properties");
$function = $_POST["func"];
$lw->debug("function=" . $function);
$plant_id = $_POST["plant-id"];
$lw->debug("plant id=" . $plant_id);
$response = "";
	
try {
	if ($function == "L") {//list
	$lw->debug("getting plants list");
		$response = Plant::getAllPlants();
	$lw->debug("got plants list");
	} else if ($function == "I") {//individual inquiry
		$lw->debug("getting plant " . $plant_id);
			$response = Plant::getPlant($plant_id);
		$lw->debug("got plant");
	} else if ($function == "E") {//edit
		if (intval($plant_id) == 0) { // new plant > ADD
		$lw->debug("adding plant " . $_POST["plant-name"]);
			$response = Plant::addPlant($_POST["plant-name"], intval($_POST["availability"]));
		$lw->debug("added plant");
		} else { // existing plant > UPDATE
		$lw->debug("Updating plant " . $plant_id);
			$response = Plant::updatePlant($plant_id, $_POST["plant-name"], intval($_POST["availability"]));
		$lw->debug("updated plant");
		}
	}
} catch (Exception $e) {
	print var_dump($e);
}
	$lw->debug("processing response");
	include("admin_data_reponse.php");
	$lw->debug("processed response");
?>
